<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
<script type="text/javascript" th:src="@{/js/jquery.js}"></script>

  <link rel="stylesheet" th:href="@{/css/morris.css}">
  <script th:src="@{/js/jquery-2.2.3.min.js}"></script>
  <script th:src="@{/js/bootstrap.min.js}"></script>
  <script th:src="@{/js/raphael-min.js}"></script>
  <script th:src="@{/js/morris.min.js}"></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>数据统计</li>
    <li>厂商采购统计</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form th:action="@{/purchaseStatistics/lists}" method="post" name="conditionForm">
    <ul class="tools">
      <li> 所属区域：
        <select name="provinceID"  onchange="ajaxProvince(this.value)">
          <option value="">请选择省份</option>
          <option th:each="pv :${session.plist}" th:value="${pv.id}" th:text="${pv.pName}"
                  th:selected="${pur.provinceID==pv.id}" >江苏</option>
        </select>
        <select name="cityId">
          <option value="">请选择城市</option>
          <option th:value="${cityByCid!=null}?${cityByCid.id}:''"
                  th:text="${cityByCid!=null}?${cityByCid.cName}:'请选择城市'" th:selected="${cityByCid!=null}">请选择城市</option>
        </select>
      </li>
      <li> 厂商名称:
        <input type="text" name="firmName" th:value="${pur.firmName}"/>
      </li>

      <li class="subBut" onclick="query()"><img th:src="@{/images/t06.png}" />查询</li>
      <li class="subBut" onclick="empty()"><img th:src="@{/images/t03.png}"/>清空</li>
    </ul>
    <table class="tablelist">
      <thead>
        <tr>
          <th>序号</th>
          <th>厂商名称</th>
          <th>负责人</th>
          <th>所属区域</th>
          <th>采购单数量</th>
          <th>金额</th>
          <th>采购单明细</th>
        </tr>
      </thead>
      <tbody>
        <tr th:each="p,var:${pinPS.list}">
          <td th:text="${(pinPS.pageNum-1)*pinPS.pageSize+var.count}">1</td>
          <td th:text="${p.firmName}">阿里巴巴</td>
          <td th:text="${p.firmFounder}">马云</td>
          <td th:text="${p.province.pName+p.city.cName}">江苏南京</td>
          <td th:text="${p.purchaseNumber}">5</td>
          <td th:text="'￥'+${p.money}">￥9,876,582</td>
          <td>
          	<a th:href="@{/purchaseStatistics/details?firmId=}+${p.firmId}" class="tablelink">查看详情</a>
          </td>
        </tr>
      </tbody>
    </table>
    <div class="pagin">
      <div class="message">共<i class="blue" th:text="${pinPS.total}">1256</i>条记录，当前显示第&nbsp;<i class="blue" th:text="${pinPS.pageNum}">2&nbsp;</i>页</div>
      <ul class="paginList">
        <li class="paginItem" th:onclick="goPage([[${pinPS.pageNum-1}]])"><a href="javascript:;"><span class="pagepre"></span></a></li>
        <li class="paginItem" th:onclick="goPage(1)" th:class="${pinPS.pageNum==1?'paginItem current':'paginItem'}"><a href="javascript:;">1</a></li>

        <li th:each="p:${listPage}" th:class="${pinPS.pageNum==p?'paginItem current':'paginItem'}" th:onclick="goPage([[${p}]])"><a th:text="${p}" href="javascript:;">2</a></li>

        <li class="paginItem" th:if="${pinPS.pages!=1 and pinPS.pages!=0}" th:onclick="goPage([[${pinPS.pages}]])" th:class="${pinPS.pageNum==pinPS.pages?'paginItem current':'paginItem'}"><a href="javascript:;" th:text="${pinPS.pages}" id="pages" >10</a></li>
        <li class="paginItem"  th:onclick="goPage([[${pinPS.pageNum+1}]])"><a href="javascript:;"><span class="pagenxt"></span></a></li>
      </ul>
    </div>
  </form>
</div>
<!-- BAR CHART -->
<div style="width: 600px;margin:auto">
  <div>
    <h3>条形统计图</h3>
  </div>
  <div>
    <div class="chart" id="bar-chart" ></div>
  </div>
</div>
<script>
  $(function() {
    $.get("/erp/purchaseStatistics/ajaxPur",function (data) {
      //BAR CHART
      new Morris.Bar({
        element: 'bar-chart',
        resize: true,
        data: data,
        barColors: ['#00a65a', '#f56954'],
        xkey: 'firmName',
        ykeys: ['purchaseNumber', 'money'],
        labels: ['采购单数量', '总金额(单位/万)'],
        hideHover: 'auto'
      });

    },"json");
  });
</script>

<script type="text/javascript">
  // 清空查询条件
  function empty() {
    $("input[name=firmName]").val("");
    $("select[name=provinceID]").val("");
    $("select[name=cityId]").val("");
  }

  // 省市级联
  function ajaxProvince(pid){
    $.get("/erp/storage/ajaxProvince",{"pid":pid},function (data) {
      $("select[name=cityId]").html();  // 清空

      var str = "<option value=''>请选择城市</option>";
      $.each(data,function (i,e) {
        str += "<option value="+e.id+">"+e.cname+"</option>";
      });
      $("select[name=cityId]").html(str);  // 添加元素

    },"json");
  }

  // 表单提交
  function query(){
    $("form[name=conditionForm]").submit();
  }

  // 页面跳转
  function goPage(num){
    var provinceID = $("select[name=provinceID]").val();
    var cityId = $("select[name=cityId]").val();
    var firmName = $("input[name=firmName]").val();

    // 最后一页
    var pages = $("#pages").text();
    if(num>=1 && num<=pages){
      location.href="/erp/purchaseStatistics/lists?pageno="+num+"&provinceID="+provinceID+"&cityId="+cityId+"&firmName="+firmName;
    }
  }

  $('.tablelist tbody tr:odd').addClass('odd');
</script>
</body>
</html>
